package com.yanqu.road.utils.energy;

/**
 * @author ：chenweijie
 * @date ：2024/5/25 17:28
 */
public class EnergyUtils {

    /**
     * 体力回复
     * @param lastRestoreTime   最后一次体力回复时间 ms
     * @param restoreEndTime    体力回复的截止时间 ms
     * @param restoreDuration   回复体力间隔时间 s
     * @param restorePerTimes   每次间隔回复的体力值
     * @param maxEnergy         体力最大值
     * @param curEnergy         当前体力值
     * @return
     */
    public static EnergyRestoreResult energyRestore(long lastRestoreTime, long restoreEndTime, long restoreDuration, int restorePerTimes, long maxEnergy, long curEnergy) {
        if (curEnergy >= maxEnergy) {
            return new EnergyRestoreResult(curEnergy, restoreEndTime);
        }
        int restoreTimes = (int) ((restoreEndTime - lastRestoreTime) / (restoreDuration * 1000));
        int restoreEnergy = restoreTimes * restorePerTimes;
        curEnergy = Math.min(curEnergy + restoreEnergy, maxEnergy);
        if (curEnergy >= maxEnergy) {
            return new EnergyRestoreResult(curEnergy, restoreEndTime);
        }
        return new EnergyRestoreResult(curEnergy, lastRestoreTime + restoreTimes * restoreDuration * 1000);
    }
}
